package com.fitt.web.fottoapp.utils

import javax.servlet.http.Cookie
import javax.servlet.http.HttpServletRequest

/**
 * <p> Description	: fottoapp </p>
 * <p> Copyright	: Copyright (c) 2016 by PCI-SUNTEK</p>
 * <p> Author 		: ZCCHUN </p>
 * <p> Create		: 2016-04-17 12:58 </p>
 * <p> version 		: 1.0 </p>
 */
enum CookieHelper {
    INSTANCE;

    void addCookie(name, value, timeLong) {
        Cookie cookie = new Cookie(name, value)
        cookie.maxAge = timeLong
        // ServletActionContext.getResponse().addCookie(cookie
    }

    String getCookie(name) {
        HttpServletRequest request = ServletActionContext.getRequest()
        Cookie[] cookies = requset.getCookies()
        if (cookies != null) {
            cookies.each {cookie ->
                if (cookie.name.equals(name)) {
                    return cookie.value
                }
            }
        }

        null
    }
}